/*
 * @Author: cyq
 * @Date: 2023-07-02 19:10:14
 * @Last Modified by: cyq
 * @Last Modified time: 2023-07-02 20:18:25
 */

import { request } from "@/utils/request";
import { API_HOME_CONFIG } from "@/config/api/home";
// import { HomeMent } from "@/interfase/module/home";
import { AxiosError } from "axios";

interface HomeuseUserFace {
  getswiper: (params: {
    type?: number;
    pagesize?: number;
    pagecount?: number;
  }) => Promise<any>;
  getGoods: (params: { pagesize?: number; pagecount?: number }) => Promise<any>;
}

export const HomeuserServe = (): HomeuseUserFace => {
  class HomeUserS {
    //轮播图
    public getswiper(params: {
      type?: number;
      pagesize?: number;
      pagecount?: number;
    }) {
      const url = API_HOME_CONFIG.getswiper();
      return request
        .get(url, { params })
        .then(({ data }: any) => {
          return Promise.resolve(data);
        })
        .catch((error: AxiosError) => {
          return Promise.reject(error);
        });
    }

    // 商品列表
    public getGoods(params: { pagesize?: number; pagecount?: number }) {
      const url = API_HOME_CONFIG.getGoods();
      return request
        .get(url, { params })
        .then(({ data }: any) => {
          return Promise.resolve(data);
        })
        .catch((err: AxiosError) => {
          return Promise.reject(err);
        });
    }
  }
  return new HomeUserS();
};
